var plane = $(".plane"),
    universe = $(".universe"),
    space = $(".space"),
    start_place = $(".start_place");


function running() {
    start_place.before("<div class='space'></div>");
    space = $(".space");
    plane.html("");
    plane.append("<img src='images/game_start/plane.png '>")

    space.addClass("space_move")
    start_place.addClass("move");

    // setTimeout(() => {
    //     start_place.remove();
    // }, 3000);
    start_place.on("animationend", function() {
        start_place.remove();
    })

    var timer = setInterval(() => {
        space.before("<div class='space_rock'></div>");
        for (var i = 0; i < 5; i++) {
            var rd_num = Math.ceil(Math.random() * 5),
                rock_top = Math.floor(Math.random() * 85),
                rock_left = Math.floor(Math.random() * 75),
                space_rock = $(".space_rock");
            var new_rock = document.createElement("img");
            space_rock.append(new_rock)
            $(new_rock).attr("src", "images/game_start/rock" + rd_num + ".png");
            $(new_rock).css("top", rock_top + "%");
            $(new_rock).css("left", rock_left + "%");
        }
        space_rock.addClass("space_move");
        space_rock.on("animationend", function() {
            space_rock.eq(0).remove();
        })
    }, 1300);
}

// 何绍靖
// 获取小飞机
var js_plane = document.querySelector(".plane");
var btn_left = document.querySelector(".btn_left");
var btn_right = document.querySelector(".btn_right");
// 控制running()数量，禁止多次执行此函数
// running()函数功能：场景切换，生成石头
var running_bool = true;
mask_close.addEventListener("click",function(){
    //自定义动画：填入4个参数，元素，json，定时器毫秒，动画执行完毕的回调函数(可选)
    // 关闭遮罩层
    mYanimate(universe_mask,{"opacity":0},50,function(){
        // 关闭遮罩层后执行
       if(running_bool){
            running_bool = false;
            running();
       }
    //    document.addEventListener("touchstart",function(e){
    //     //    console.log(js_plane.offsetLeft);
    //         var pagex = e.targetTouches[0].clientX;
    //         document.addEventListener("touchmove",function(e){
    //             var pagex_move = e.targetTouches[0].clientX;
    //             var x = pagex_move - pagex;
    //             // js_plane.setAttribute("style","left:"+x+"px;");
    //             // console.log(js_plane);
    //             js_plane.style.left = (js_plane.offsetLeft+x)+"px";
    //             console.log(js_plane.style.left);
    //         })
    //    })
    });
})
console.log(btn_left);
btn_left.addEventListener("click",function(){
    this.style.transform = "translateX(-100%)";
    console.log(1);
})